//
//  BN_KinderGartenHelperTest.m
//  BabyNow
//
//  Created by 闫建刚 on 14-5-20.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "XCTestAsync.h"
#import "BN_KinderGartenHelper.h"

@interface BN_KinderGartenHelperTest : XCTestCase
{
    BN_KinderGartenHelper *helper_;
}

@end

@implementation BN_KinderGartenHelperTest

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    helper_ = [[BN_KinderGartenHelper alloc]init];
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
    helper_ = nil;
}

- (void)xctAssertNil:(NSString *)errorMsg{
    XCTAssertNil(errorMsg);
}

- (void)xcAsyncSuccess{
    XCAsyncSuccess();
}

// 测试查询第一页美食列表
- (void)testQueryFoodListAsync{
    __weak typeof(self) weakSelf = self;
    helper_.queryFoodListCompleteHandler = ^(id result,NSString* errorMessage){
        if (errorMessage) {
            [weakSelf xctAssertNil:errorMessage];
        }else{
            NSLog(@"美食列表：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [helper_ refreshFoodList];
}

// 测试查询第一页活动列表
- (void)testQueryActionListAsync{
    __weak typeof(self) weakSelf = self;
    helper_.queryActionListCompleteHandler = ^(id result,NSString* errorMessage){
        if (errorMessage) {
            [weakSelf xctAssertNil:errorMessage];
        }else{
            NSLog(@"活动列表：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [helper_ refreshActionList];
}

// 测试查询美食详情
- (void)testQueryFoodDetailAsync{
    NSString *foodId = @"3";
    __weak typeof(self) weakSelf = self;
    [helper_ queryFoodDetailById:foodId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"美食详情：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试发布美食
- (void)testSendFoodAsync{
    __weak typeof(self) weakSelf = self;
    NSString *notiSubj = @"2014-05-20食谱???";
    NSString *notiCont = @"西红柿炒鸡蛋++++++大米饭";
    NSString *fileName1 = @"tomato_egg.jpg";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"tamato_egg" ofType:@"jpg"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];

    // 封装一张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}
                             ];
    [helper_ sendFoodNotiSubj:notiSubj notiCont:notiCont fileInfoArr:nil completeHandler:^(id result, NSString *errMsg) {
        if (result) {
            NSLog(@"发布美食结果：%@",result);
        }else{
            NSLog(@"发布美食出错：%@",errMsg);
        }
        [weakSelf xcAsyncSuccess];
    } uploadProcessingHandler:^(double process) {
        NSLog(@"发布美食进度:%f",process);
    }];
}

// 测试删除美食
- (void)testRemoveFoodAsync{
    __weak typeof(self) weakSelf = self;
    NSString *foodId = @"3";
    [helper_ removeFoodById:foodId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"删除美食：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询活动详情
- (void)testQueryActionDetailAsync{
    NSString *actiId = @"3";
    __weak typeof(self) weakSelf = self;
    [helper_ queryActionDetailById:actiId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"活动详情：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试发布活动
- (void)testSendActionAsync{
    __weak typeof(self) weakSelf = self;
    NSString *notiSubj = @"2014-05-20 上午发布";
    NSString *notiCont = @"明天去春游喽";
    
    NSString *fileName1 = @"ios8.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"ios8" ofType:@"png"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    // 封装一张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}];
    [helper_ sendActionNotiSubj:nil notiCont:nil fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (result) {
            NSLog(@"发布活动结果：%@",result);
        }else{
            NSLog(@"发布活动出错：%@",errMsg);
        }
        [weakSelf xcAsyncSuccess];
    } uploadProcessingHandler:^(double process) {
        NSLog(@"发布活动进度:%f",process);
    }];
}

// 测试删除活动
- (void)testRemoveActionAsync{
    __weak typeof(self) weakSelf = self;
    NSString *actiId = @"3";
    [helper_ removeActionById:actiId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"删除活动：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询幼儿园简介
- (void)testQueryKgBrieInfoAsync{
    __weak typeof(self) weakSelf = self;
    [helper_ queryKgDetail:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"删除活动：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试发布幼儿园简介
- (void)testSendKgBrieInfoAsync{
    __weak typeof(self) weakSelf = self;
    NSString *briefContent = @"ABC幼儿园，儿童的摇篮......";
    NSString *fileName1 = @"children.jpg";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"children" ofType:@"jpg"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    // 封装一张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}];
    [helper_ sendKgInfoWithBrieCont:briefContent fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (result) {
            NSLog(@"幼儿园简介发布结果:%@",result);
        }else{
            NSLog(@"幼儿园简介发布失败:%@",errMsg);
        }
        [weakSelf xcAsyncSuccess];
    } uploadProcessingHandler:^(double process) {
        NSLog(@"发布幼儿园简介进度:%f",process);
    }];
}


// 测试更新幼儿园简介
- (void)testUpdateKgBrieInfoAsync{
    __weak typeof(self) weakSelf = self;
    NSString *briefId = @"1";
    NSString *briefContent = @"update幼儿园ABC";
    NSString *fileName1 = @"gotoschool.jpg";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"gotoschool" ofType:@"jpg"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    // 封装一张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}];
    
    [helper_ updateKgInfoWithBrieId:briefId BrieCont:briefContent fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (result) {
            NSLog(@"幼儿园简介更新结果:%@",result);
        }else{
            NSLog(@"幼儿园简介更新失败:%@",errMsg);
        }
        [weakSelf xcAsyncSuccess];
    } uploadProcessingHandler:^(double process) {
        NSLog(@"更新幼儿园简介进度:%f",process);
    }];
}

// 测试查询第一页园长信箱列表
- (void)testQuerySuggestListAsync{
    __weak typeof(self) weakSelf = self;
    helper_.querySuggestListCompleteHandler = ^(id result,NSString* errorMessage){
        if (errorMessage) {
            [weakSelf xctAssertNil:errorMessage];
        }else{
            NSLog(@"园长信箱列表：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [helper_ refreshSuggestList];
}

// 测试查询园长信箱详情
- (void)testQuerySuggestInfoAsync{
    NSString *suggId = @"1";
    __weak typeof(self) weakSelf = self;
    [helper_ querySuggestInfoById:suggId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"园长信箱详情：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试发布园长信箱
- (void)testSendSuggestInfoAsync{
    __weak typeof(self) weakSelf = self;
    NSString *suggSubj = @"Hello master 2";
    NSString *suggCont = @"园长您好，我向您反映一下关于幼儿园伙食的问题 2";
    NSString *fileName1 = @"tamato_egg.jpg";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"tamato_egg" ofType:@"jpg"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    // 封装一张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}];
    
    [helper_ sendSuggestInfoWithSuggSubj:suggSubj SuggCont:suggCont fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (result) {
            NSLog(@"园长信箱发布结果:%@",result);
        }else{
            NSLog(@"园长信箱发布失败:%@",errMsg);
        }
        [weakSelf xcAsyncSuccess];
    } uploadProcessingHandler:^(double process) {
        NSLog(@"发布园长信箱进度:%f",process);
    }];
    
}

// 测试删除园长信箱
- (void)testRemoveSuggestByIdAsync{
    __weak typeof(self) weakSelf = self;
    NSString *suggId = @"1";
    [helper_ removeSuggestById:suggId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"删除编号为%@的园长信箱：%@",suggId,result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}



@end
